const pool = require('../config/config.default')



module.exports.getUser = async (user) =>{
  pool.getConnection((err, conn)=>{
    try{
      if(err){
        console.log(err)
      }else {
        console.log('success')
      }
    }finally{
      console.log('conn.release ...')
      conn.release()
    }
  })
}

module.exports.register = async (user, next) =>{
  pool.getConnection((err, conn)=>{
    try{
      conn.query('insert into students(studentname, loginpwd, email) values(?, ?, ?)',
      [
        user.username,
        user.password,
        user.email
      ],
      (err, result)=>{
        if(err){  
          console.log('插入数据失败');
          throw err   
        }else{  
          console.log('插入数据成功');
        }
      })
    }catch(err){
      console.log(err)
    }finally{
      console.log('conn.release ...')
      conn.release()
      next()
    }
  })
}